﻿using AutoMapper.Internal.Mappers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Domain.Repositories;

namespace Himp.DataHub
{
    /// <summary>
    /// 诊断疾病字典
    /// </summary>
    public class DiseDiagDictService: DataHubAppService
    {
        private IRepository<DiseDiagDict, Guid> _DiseDiagDictRepository;

        public DiseDiagDictService(IRepository<DiseDiagDict, Guid> DiseDiagDictRepository) 
        {
            _DiseDiagDictRepository = DiseDiagDictRepository;
        }

        public async Task<PagedResultDto<DiseDiagDictDto>> GetListAsync(DiseDiagDictInput input)
        {
            var iQuery = await _DiseDiagDictRepository.GetQueryableAsync();

            if (input.Pi == 0)
            {
                var itemsDto = ObjectMapper.Map<List<DiseDiagDict>, List<DiseDiagDictDto>>(iQuery.ToList());

                return new PagedResultDto<DiseDiagDictDto>(itemsDto.Count, itemsDto);
            }
            else
            {
                var totalCount = iQuery.Count();
                var items = iQuery.Page(input.Pi, input.Ps);
                var itemsDto = ObjectMapper.Map<List<DiseDiagDict>, List<DiseDiagDictDto>>(items.ToList());

                return new PagedResultDto<DiseDiagDictDto>(totalCount, itemsDto);
            }
        }
    }
}
